import { ref, reactive } from 'vue'
import { myEvaluateCount, myEvaluateList } from '@/utlis/interface/Wode'
export default (Proxy: any) => {
    // tabs样式
    const inactiveStyle = reactive({
        color: '#000',
        transform: 'scale(1)',
    })
    const activeStyle = reactive({
        color: '#000',
        fontWeight: 'bold',
        transform: 'scale(1.1)',
    })
    // tabs数组
    const list = reactive([
        {
            name: '满意',
            Type: 1,

        },
        {
            name: '不满意',
            Type: 0,

        },
    ])

    const myEvlation = reactive<any>({
        list: []

    })
    // tabs分类默认值
    const baseData = reactive({
        degree: 1,
        pageNo: 1,
        pageSize: 10,
        toLower_show: true
    })
    // tabs切换
    const Tabs = (item: any) => {
        baseData.degree = list[item.index].Type;
        baseData.pageNo = 1
        baseData.toLower_show = true
        myEvlation.list = []
        getEvlationLsit()
    }
    // 列表触底加载数据
    const scrollTop = ref(0)

    const toLower = (e: any) => {
        if (baseData.toLower_show) {
            baseData.pageNo++
            getEvlationLsit()
        } else {

            Proxy.$API(Proxy).Toast('暂无更多数据', 'warning')
        }


    }
    //获取用户评价数量
    const getEvlationCount = () => {
        myEvaluateCount(Proxy)
            .then((res: any) => {
                if (res.code == 0) {
                    list[0].name = `满意(${res.data.goodCount > 99 ? '99+' : res.data.goodCount})`
                    list[1].name = `不满意(${res.data.badCount > 99 ? '99+' : res.data.badCount})`
                }
            })
            .catch((err: any) => {
                if (err.code == -1) {
                    Proxy.$API(Proxy).Toast(err.msg, 'error')
                }
            })
    }
    // 获取列表
    const getEvlationLsit = () => {
        let data = {
            degree: baseData.degree,
            pageNo: baseData.pageNo,
            pageSize: baseData.pageSize,

        }
        myEvaluateList(data, Proxy).then((res: any) => {
            if (res.code == 0 && res.data.length > 0) {
                res.data.forEach((item: any, index: any) => {
                    let obj = {
                        userId: item.userId,
                        time: item.time,
                        remark: item.remark,
                        name: '匿名用户',
                        avatar: item.avatar
                    }
                    myEvlation.list.push(obj)
                })


            } else {
                baseData.toLower_show = false

            }
        }).catch((err: any) => {

            if (err.code == -1) {
                Proxy.$API(Proxy).Toast(err.msg, 'error')
            }
        })
    }

    return {
        inactiveStyle,
        activeStyle,
        myEvlation,
        Tabs,
        list,
        baseData,
        getEvlationCount,
        getEvlationLsit,
        scrollTop,
        toLower
    }
}
